package labelsystem.Service.Implements;/**
 * @projectName careOlder
 * @Description TODO
 * @author MCG
 * @time 2023/3/26 20:58
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import labelsystem.Mapper.orderMapper;
import labelsystem.Mapper.videoMapper;
import labelsystem.Mapper.volunteerMapper;
import labelsystem.Mapper.textMapper;
import labelsystem.Pojo.Order;
import labelsystem.Pojo.Text;
import labelsystem.Pojo.Video;
import labelsystem.Pojo.Volunteer;
import labelsystem.Service.volunteerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *description: TODO
 *@author MCG
 *@date 2023/3/26 20:58
 *@Version 1.0
 */
@Service
public class volunteerServiceImplement implements volunteerService {
    @Resource
    volunteerMapper volunteerMapper;
    @Resource
    orderMapper orderMapper;
    @Resource
    textMapper textMapper;
    @Resource
    videoMapper videoMapper;
    @Override
    public boolean loginInByPassword(String telephone, String password) {
        QueryWrapper<Volunteer> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("phone",telephone);
        return password.equals(volunteerMapper.selectOne(queryWrapper));

    }

    @Override
    public boolean loginInByCode(String input, String code) {
        return input.equals(code);
    }

    @Override
    public Volunteer register(String name, Long phone, int age, String gender, String password, Float price, Float rating, int experience, String crl) {
        Volunteer volunteer=new Volunteer();
        volunteer.setName(name);
        volunteer.setPrice(price);
        volunteer.setAge(age);
        volunteer.setPhone(phone);
        volunteer.setPassword(password);
        volunteer.setGender(gender);
        volunteer.setCertificate(crl);
        volunteer.setExperience(experience);
        volunteer.setRating(rating);
        volunteerMapper.insert(volunteer);
        return volunteer;
    }

    @Override
    public Volunteer queryInfo(Long vid) {
        return volunteerMapper.selectById(vid);
    }


    @Override
    public Volunteer queryInfoByTel(Long phone) {
        QueryWrapper<Volunteer> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        return volunteerMapper.selectOne(queryWrapper);
    }

    @Override
    public boolean saveText(Long vId, String url) {
        Text text=new Text();
        text.setUrl(url);
        text.setOffId(vId);
        text.setType("1");
        return 1==textMapper.insert(text);
    }

    @Override
    public boolean saveVideo(Long vId, String url) {
        Video video=new Video();
        video.setUrl(url);
        video.setOffId(vId);
        video.setCreateType("0");
        return 1==videoMapper.insert(video);
    }

    @Override
    public List<Order> selectListById(Long vid) {
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("offer_id",vid).eq("type","1");
        return orderMapper.selectList(queryWrapper);
    }

    @Override
    public List<Text> selectTextById(Long vid) {
        QueryWrapper<Text> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("offer_id",vid).eq("create_type","1");
        return textMapper.selectList(queryWrapper);
    }

    @Override
    public List<Video> selectVideoById(Long vid) {
        QueryWrapper<Video> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("offer_id",vid).eq("create_type","1");
        return videoMapper.selectList(queryWrapper);
    }

    @Override
    public boolean updateVolunteer(Volunteer volunteer) {
        return 1==volunteerMapper.updateById(volunteer);
    }
}
